import {
	getStore,
	setStore
} from '_c/utils/store'
import {
	login,
	logout
} from '_a/login'
import {
	agentInfo
} from "_a/myInfo";
import {
	getSysParam
} from "_a/sms";
import tip from '_c/utils/tip'
const system = {
	state: {
		appClearVersion: '1.0.1', //清除ios缓存用
		balanceList: getStore('balanceList') || [], //钱包列表
		totalTypeList: getStore('totalTypeList') || [], //交易类型
		commonlevelList: [],
		bannerHomeList: getStore('bannerHomeList') || [],
		bannerShopList: getStore('bannerHomeList') || [],
		sharePoster: [],
		appConfig: getStore('appConfig') || null, //app配置 
	},
	actions: {
		// 检查ios本地版本,是否需要清除缓存
		checkIosAppLocalVersion(store, serveVersion) {
			console.log({store, serveVersion})
			let localVersion = getStore(
				'appLocalVersion'
			) || ''
			// alert(serveVersion+':'+localVersion)
			if (localVersion == '' || localVersion !== serveVersion) {
				// tip.modal({
				// 	content: "缓存清除提示!",
				// 	showCancel: false,
				// }).then(res => {
				// 	setStore(
				// 		'appLocalVersion',
				// 		serveVersion
				// 	)
				// 	window.location.reload(true)
				// });
				setStore(
					'appLocalVersion',
					serveVersion
				)
				window.location.reload(true)
			}
		},
		async getUserLevelList({
			commit
		}, data) {
			let list = getStore('commonlevelList') || ''
			if (list && list.length) {
				commit('SETCommonLevelList', list)
			} else {
				let commonLevelValue = await getSysParam({
					code: "agent_common_level"
				});
				// this.superlevelList = JSON.parse(superLevelValue.data.value) || [];
				commit('SETCommonLevelList', JSON.parse(commonLevelValue.data.value) || [])
			}

		}
	},
	mutations: {
		SETAppConfig: (state, value) => {
			state.appConfig = value
			setStore(
				'appConfig',
				value
			)
		},
		SETTerminalInto: (state, value) => {
			state.terminalInto = value
			setStore(
				'terminalInto',
				value
			)
		},
		SETCommonLevelList: (state, value) => {
			state.commonlevelList = value
			setStore(
				'commonlevelList',
				value
			)
		},
		setBalanceList(state, value) {
			state.balanceList = value
			setStore('balanceList', state.balanceList)
		},
		setTotalTypeList(state, value) {
			state.totalTypeList = value
			setStore('totalTypeList', state.totalTypeList)
		},

		setBannerList(state, value) {
			state.bannerHomeList = value.filter((item) => {
				return item.bannerType == 1 && item.isShow;
			})
			state.bannerShopList = value.filter((item) => {
				return item.bannerType == 2 && item.isShow;
			})
			setStore(
				'bannerList',
				value
			)
			setStore('bannerHomeList', state.bannerHomeList)
			setStore('bannerShopList', state.bannerShopList)
		},
		setSharePoster(state, value) {
			state.sharePoster = value.filter((item) => {
				return item.isShow;
			})
			setStore(
				'sharePoster',
				value
			)
		},
	}
}
export default system